<?php
	$results = '<div class="aTableHeader" id="tabs_'.$asession['Asession']['id'].'">
	<span class="aTableAction">Question</span>
	<span class="aTableResult">Answer</span>
	<span class="aTableCorrect">Correct</span>
	<span class="aTableMarks">Marks Earned</span></div>';
	$total_marks = 0;
	$result = '';
	$i = 0;
	$j = 0;
	$result_value2 = '';
	$questiongroup_id = 0;
	foreach ($asession['Asessionlog'] as $result)
	{
		//if($j == 0)
			//print_r($result);
		$result_value = '';
		$marks  = '';
		$correct  = '';
		$action = '';
		$action2 = '';
		if($result['questiongroup_id'] > 0 && $result['questiongroup_id'] != $questiongroup_id)
		{
			if($i == 0)
				$i = 1;
			else 
				$i = 0;
				
				$questiongroup_id = $result['questiongroup_id'];
		}
		
		if ($result['question_id'] > 0 && $result['answer'] == 0)
		{
			$result_value2 = @$result['Question']['question'];
			
		}
		elseif ($result['question_id'] == 0 && $result['answer'] > 0)
		{
			$action = @$result_value2;
			$result_value = @$result['AnswerGiven']['Answer']['answer_text'];
			$action2 = '';
			$result_value2 = '';
			if ($result['correct'] == 1)
			{
				$correct = 'true';
				$marks = @$result['AnswerGiven']['Question']['marks_awarded'];
				$total_marks += @$result['AnswerGiven']['Question']['marks_awarded'];
			}
			else
			{
				$marks = 0;
				$total_marks += 0;
				$correct = 'false';
			}

		}
		if($result_value == '' || $action == 'complete')
		{
			
			if(array_key_exists('message', $result))
			{
				if($correct == '' && $result['message'] != '')
				{
					$action = "<p style='color:red;'>" . $result['message'] . "</p>";
				}
			}
			else 
				continue;
		}
		
		if($result_value == '')
			continue;
		
		if($i == 0)
			$results .=  '<div class="aTableRowA">';
		else
			$results .=  '<div class="aTableRowB">';
		
		if($correct == 'true')
			$correct = '<img src="/img/tick.png">';
		else if($correct == 'false')
			$correct = '<img src="/img/cross.png">';
		else
			$correct = '';

		$results .= '<span class="aTableAction">'.$action.'&nbsp;</span><span class="aTableResult">'.$result_value.'&nbsp;</span><span class="aTableCorrect">'.$correct.'&nbsp;</span><span class="aTableMarks">'.$marks.'&nbsp;</span></div>';

	}

	$results .= '<div class="aTableHeader"><span class="aTableResult"><b>Total Marks</b></span><span class="aTableResult"></span><span class="aTableResult"><b>'.$total_marks.'</b></span></div>';

	$results .= '';
	

	print $results;

?>